﻿using System;

using ApplicationLibrary;
using ApplicationLibrary.SqlConnector;

namespace ProjectManager.Masters.ModuleData
{
    internal class RegisterModule : ApplicationLibrary.SqlConnector.RegisterModule
    {
        public override string Application()
        {
            return "PRJM";
        }

        public override string Module()
        {
            return "MAST";
        }

        public override int CurrentVersion()
        {
            return 1;
        }

        public override Version DllVersion
        {
            get
            {
                return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
            }
        }

        public override void RegisterCountersAndCodes()
        {
            GlobalInfo.AddCounter(Counters.Project.Int(), Properties.Resources.C_Projects);
            GlobalInfo.AddCounter(Counters.Improvement.Int(), Properties.Resources.C_Improvements);
            GlobalInfo.AddCounter(Counters.Step.Int(), Properties.Resources.C_Steps);
            GlobalInfo.AddCounter(Counters.Session.Int(), Properties.Resources.C_Sessions);
            GlobalInfo.AddCounter(Counters.Bug.Int(), Properties.Resources.C_Bugs);
        }

        public override void AddScrounger(ApplicationLibrary.DBManager.iScrounger frm, NameSpace nameSpace)
        {
            if (nameSpace.ApplicationPath == "ProjectManager.Masters.Forms.Bugs" ||
                nameSpace.ApplicationPath == "ProjectManager.Masters.Forms.Projects" ||
                nameSpace.ApplicationPath == "ProjectManager.Masters.Forms.Improvements" ||
                nameSpace.ApplicationPath == "ProjectManager.Masters.Forms.Steps"
                )
                frm.ScroungerList.Add(new ProjectManager.Masters.Scrounger.SessionsScrounger(frm));
        }

        public override ApplicationLibrary.Preferences.PreferencePanel[] RegisterPreferences()
        {
            //return new ApplicationLibrary.Preferences.PreferencePanel[]
            //{
            //    new AccountingPreferencePanel()
            //};
            return null;
        }

        protected override bool CreateDBTables()
        {
            SqlCreateTable newTable = new SqlCreateTable(SqlABConnection);

            #region PM_Descriptions

            if (SearchTable(PM_Descriptions.Name))
            {
                newTable.NewTable(PM_Descriptions.Name);

                newTable.AddColumn(PM_Descriptions.Type);
                newTable.AddColumn(PM_Descriptions.Code);
                newTable.AddColumn(PM_Descriptions.Description);

                newTable.AddPrimaryKey(new iColumn[] { PM_Descriptions.Type, PM_Descriptions.Code });

                newTable.Create();
            }

            #endregion PM_Descriptions

            #region PM_Project

            if (SearchTable(PM_Project.Name))
            {
                newTable.NewTable(PM_Project.Name);

                newTable.AddColumn(PM_Project.Type);
                newTable.AddColumn(PM_Project.Code);
                newTable.AddColumn(PM_Project.Description);
                newTable.AddColumn(PM_Project.Date);
                newTable.AddColumn(PM_Project.Product);
                newTable.AddColumn(PM_Project.Version);
                newTable.AddColumn(PM_Project.Status);
                newTable.AddColumn(PM_Project.StartingDate);
                newTable.AddColumn(PM_Project.EndingDate);
                newTable.AddColumn(PM_Project.FatherType);
                newTable.AddColumn(PM_Project.Father);
                newTable.AddColumn(PM_Project.Note);

                newTable.AddPrimaryKey(new iColumn[] { PM_Project.Type, PM_Project.Code });

                newTable.Create();
            }

            #endregion PM_Project

            #region PM_Session

            if (SearchTable(PM_Session.Name))
            {
                newTable.NewTable(PM_Session.Name);

                newTable.AddColumn(PM_Session.ID);
                newTable.AddColumn(PM_Session.Type);
                newTable.AddColumn(PM_Session.Code);
                newTable.AddColumn(PM_Session.Description);
                newTable.AddColumn(PM_Session.StartDate);
                newTable.AddColumn(PM_Session.EndDate);

                newTable.AddPrimaryKey(new iColumn[] { PM_Session.ID });

                newTable.Create();
            }

            #endregion PM_Session

            return true;
        }

        protected override bool UpdateDBTables()
        {
            return true;
        }
    }
}